<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        div {
            width: 100px;
            height: 100px;
            background-color: black;
            display: inline-block;
        }
    </style>
</head>

<body>
    <button onclick="add()">点击将DIV变成红色</button>
    <div></div>
    <div></div>
    <div></div>
</body>
<script>
    let divs = document.getElementsByTagName('div')
    function add() {
        for (let index = 0; index < divs.length; index++) {
            divs[index].style.backgroundColor = 'red'
        }
    }
</script>

</html>